package route

import (
	"chatgpt/controller"
	"chatgpt/controller/app"
	"chatgpt/controller/middleware"
	"chatgpt/helper"
	"github.com/gin-gonic/gin"
)

func Run() {
	router := gin.Default()
	router.Use(middleware.Cors())
	register(router)
	appRouter(router)
	vp := helper.Config().Sub("Server").Sub("http")
	router.Run(vp.GetString("addr"))
}

func register(router *gin.Engine) {
	//router.Any("/system/login", controller.HandleLogin)

	//system := router.Group("/system", middleware.MustLogin())
	apir := router.Group("/question", middleware.ApiKeyCheck(), middleware.RawData())
	apir.Any("/quick", controller.QuestionHandle)
	apir.Any("/origin", controller.OriginHandle)
	image := router.Group("/image", middleware.ApiKeyCheck())
	image.Any("/generate", controller.ImageGenerateHandle)

	v1 := router.Group("/v1", middleware.ApiKeyCheck(), middleware.RawData())

	v1.Any("/completion", controller.CompletionHandle)
	v1.Any("/chat", controller.ChatHandle)
	v1.Any("/image-gen", controller.ImageGenerateHandle)

	fine_tune := v1.Group("/fine-tunes")
	fine_tune.Any("/list", controller.FineTuneListHandle)

}

func appRouter(router *gin.Engine) {
	appr := router.Group("/app")

	// common direct
	appr.Any("/completion", app.CompletionHandle)
	appr.Any("/completion-clear", app.CompletionClearHandle)
	appr.Any("/chat", app.ChatHandle)

	// fine-tune
	fine_tune := appr.Group("/fine-tunes")
	fine_tune.Any("/list", app.FineTuneListHandle)
}
